/*
 * Copyright 2012 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.tieba.view.velocity.tools;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.tools.config.DefaultKey;
import org.apache.velocity.tools.generic.SafeConfig;
import org.apache.velocity.tools.generic.ValueParser;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.fujitsu.nanjing.tieba.common.PropertyUtils;

/**
 * DomainTool.java
 * 
 * @author Qixiaobo-win8
 */
@DefaultKey("domain")
public class DomainTool extends SafeConfig {
	private static Properties context;
	protected Log LOG;
	public String info(String key) {
		// TODO;设置文件路径
		Resource r = new ClassPathResource(
				"com/fujitsu/props/context.properties");
		try {
			context = PropertyUtils.readFromResource(r);
		} catch (IOException e) {

		}
		return context.getProperty(key);
	}

	public String getCopyrightYear() {
		Calendar c = Calendar.getInstance();
		c.setTime(new Date());
		return String.valueOf(c.get(Calendar.YEAR));
	}
	public String getDomain() {
		return info("domain");
	}

	public String get() {
		return getDomain();
	}
	@Override
	protected void configure(ValueParser props) {
		LOG = (Log) props.getValue("log");
	}
}
